package dev.xesam.bottomsheet;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import dev.xesam.bottomsheet.adapter.MenuAdapter;


public class MainActivity extends AppCompatActivity {

    BottomSheet mBottomSheet;
    List<BottomSheetItem> mBottomSheetItems;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn_hello = (Button)findViewById(R.id.hello);

        setBottomSheetItem();
        mBottomSheet = new BottomSheet(MainActivity.this, BottomSheet.MENUTYPE_VERTICAL);
        mBottomSheet.setAdapter(new MenuAdapter(MainActivity.this, mBottomSheetItems, BottomSheet.MENUTYPE_VERTICAL));
        mBottomSheet.setHeaderText("收藏列表").setFooterText("取消").setNumColumnsWhenVertical(1).init();

        mBottomSheet.setOnViewItemSelectedListener(new BottomSheet.OnViewItemSelectedListener() {
            @Override
            public void onViewItemSelected(int position) {
                Toast.makeText(MainActivity.this, mBottomSheetItems.get(position).getContent(), Toast.LENGTH_SHORT).show();
            }
        });
        mBottomSheet.setOnButtonClickedListener(new BottomSheet.OnButtonClickedListener() {
            @Override
            public void onButtonClicked() {
                mBottomSheet.dismiss();
            }
        });
        btn_hello.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBottomSheet.show();
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void setBottomSheetItem() {

        mBottomSheetItems = new ArrayList<>();
        BottomSheetItem item0 = new BottomSheetItem();
        item0.setItemId(0);
        item0.setIconId(R.drawable.details);
        item0.setContent("推荐");
        mBottomSheetItems.add(item0);

        BottomSheetItem item1 = new BottomSheetItem();
        item1.setItemId(1);
        item1.setIconId(R.drawable.export);
        item1.setContent("分享一下");
        mBottomSheetItems.add(item1);

        BottomSheetItem item2 = new BottomSheetItem();
        item2.setItemId(2);
        item2.setIconId(R.drawable.open);
        item2.setContent("其他");
        mBottomSheetItems.add(item2);

        BottomSheetItem item3 = new BottomSheetItem();
        item3.setItemId(3);
        item3.setIconId(R.drawable.uninstall);
        item3.setContent("取消收藏");
        item3.setEnable(false);
        mBottomSheetItems.add(item3);
    }


}
